home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS Toolkit
/
BBS Toolkit.iso
/
pc_board
/
callerup.zip
/
TOOLS.C
< prev
next >
Wrap
Text File
|
1991-10-06
|
4KB
|
126 lines
#include <dos.h>
#include <dir.h>
#include <stdio.h>
#include <string.h>
#include "tools.h"
FILE *fPr;
Path_Slash(char *s,int flg){
while(*s!='\0')
s++;
s--;
if((strcmp(s,"\\")) && (flg==0))
strcat(s,"\\");
if((!strcmp(s,"\\")) && (flg==1)){
strcpy(s,"\0");
}
}
Getcwdname(char *s,char *rs){
char buffer[255];
getcwd(buffer,255);
strcat(buffer,"\\");
strcat(buffer,s);
strcpy(rs,buffer);}
Prt_Attr_Str(int col, int row, int color, char *s){
gotoxy(col,row);
textcolor(color);
cprintf(s);}
int Julian(int day,int month, int year) {
int runsum[] ={0,31,59,90,120,151,181,212,243,273,304,334,365};
int total;
total = runsum[month - 1]+day;
if(month > 2)
total += Leapyear(year);
return(total);}
int Leapyear(int year) {
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
return 1;
else
return 0;}
void Hex_Str(char *str) {
int i;
for (i=0;str[i] != '\0';i++)
printf ("%02x ",str[i]);}
int New_To_Null(char *str) {
char *pointer;
if((pointer = (char *) strchr(str,'\n'))!=0)
strcpy(pointer,'\0');}
void Str_Toupper(char *str) {
char *s;
s = str;
while (*s != '\0') {
*s = toupper(*s);
s++; }}
Get_Time(char *buff, int sep){
char time[3];
union REGS ireg;
ireg.h.ah=0x2c;
intdos(&ireg,&ireg);
sprintf(buff,"%02d%c%02d",ireg.h.ch,sep,ireg.h.cl);}
Get_Date(char *buff,int sep) {
char form[20];
union REGS ireg;
ireg.h.ah = 0x2a;
intdos(&ireg,&ireg);
strcpy(form,"%02d%c%02d%c%02d");
sprintf(buff,form,ireg.h.dh,sep,ireg.h.dl,sep,ireg.x.cx-1900);}
/*::::::::::::::::::::[ FILE OPERATION ROUTINES ]:::::::::::::::::::::*/
Ropenfile(char *filename){
if((fPr=fopen(filename,"r"))==NULL){
printf("%c\n\n%s file is not available!\n\n",7,filename);
exit(1); }}
Wopenfile(char *filename){
if((fPr=fopen(filename,"w"))==NULL){
printf("%c\n\n%s file is cannot be written!\n\n",7,filename);
exit(1); }}
Aopenfile(char *filename){
if((fPr=fopen(filename,"a"))==NULL){
printf("%c\n\n%s file cannot be opened!\n\n",7,filename);
exit(1); }}
Fexist(char *filename){
int stat;
stat=(fPr=fopen(filename,"r"))? 1:0;
if(stat)
fclose(fPr);
return(stat);}
Fclosefile(){
fclose(fPr);}
Freadline(char *s){
fgets(s,FileLen,fPr);
New_To_Null(s);}
Fwriteline(char *s){
fprintf(fPr,s);}
Fwritelinec(char *s){
fprintf(fPr,"%s\n",s);}
Readfile (char *filename,char *s,int linenum){
char buffer[82];
int i;
strcpy(s,'\0');
Ropenfile(filename);
for(i=1;i<linenum+1;i++)
Freadline(buffer);
strcpy(s,buffer);}
Fclosefile();
/*=======================================================================*/
Get_Dir_Info(char *findpath,char *dirbuff){
struct ffblk FblK;
int done,counter;
counter=0;
done=findfirst(findpath,&FblK,0);
strcpy(dirbuff,FblK.ff_name);
counter++;
while(!(done=findnext(&FblK)));
strcpy(&dirbuff[counter++*FileLen],FblK.ff_name);
return(counter);}
Kill_Dir(char *findpath){
char filename[FileLen];
strcpy(filename,"echo y | del ");
strcat(filename,findpath);
strcat(filename," > nul");
system(filename);}